package com.iceland.common.exception;

import io.netty.channel.*;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GlobalExceptionHandler extends ChannelDuplexHandler {
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        if(cause!=null){
            log.error("读数据异常:{} ",cause);
        }
    }

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ctx.write(msg,promise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture channelFuture) throws Exception {
                if(!channelFuture.isSuccess()){
                    log.error("写数据异常：{}",channelFuture.cause());
                }
            }
        }));
    }
}
